﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AzureGames.Data;
using AzureGames.Domain.Contracts;
using AzureGames.Domain.Models;

namespace AzureGames.Domain.Handlers
{
    public class GetGameUser
    {
        private readonly IUserRepository _userRepository;

        public GetGameUser(IUserRepository userRepository)
        {
            _userRepository = userRepository;
        }

        public virtual GameUser Execute(string userID)
        {
            try
            {
                var user = _userRepository.GetUser(userID);
                if (user != null)
                {
                    return new GameUser(user);
                }
                else
                    return null;
            }
            catch (InvalidOperationException e)
            {
                throw new BusinessServicesException("Unable to retrieve user from database.", e);
            }
        }
    }
}
